<template>
  <div id="name">
    <div class="wl-body">
      <div class="gdxq">
        <div class="gdwt bdds">
          <div class="txt">{{ $t("m.wtms") }}</div>
          <div class="gdbgs">
            <div>{{ gdata[0].content }}</div>
            <div class="imglist">
              <img
                :src="item"
                alt=""
                class="imicos"
                v-for="(item, index) in topimglist"
                :key="index"
                @click="seeimg(topimglist)"
              />
            </div>
          </div>
          <div class="times">{{ gdata[0].createTime }}</div>
        </div>
        <div class="gd-list">
          <div
            class="gd-list-item"
            v-for="(item, index) in gdata.slice(1)"
            :key="index"
          >
            <div class="gd-l">
              <div :class="[item.type == 1 ? 'imico' : 'imicom']">
                {{ item.type == 1 ? $t("m.nin") : "" }}
              </div>
              <div class="mml"></div>
            </div>
            <div class="gd-r">
              <div class="hfneir">{{ item ? item.content : "" }}</div>
              <div class="imglist" v-if="item.imgs">
                <img
                  :src="i"
                  v-for="(i, index) in forimg(item.imgs)"
                  :key="index"
                  class="imicos"
                  @click="seeimg(forimg(item.imgs))"
                />
              </div>
              <div class="gdtime">{{ item.createTime }}</div>
            </div>
          </div>
          <div class="gd-list-item" v-if="end.status == 1">
            <div class="gd-l">
              <div class="imicom"></div>
            </div>
            <div class="gd-r end">
              <div class="hfneir">{{ $t("m.dkfcl") }}</div>
            </div>
          </div>
          <div class="gd-list-item" v-if="end.status == 2">
            <div class="gd-l">
              <div class="imico">{{ $t("m.nin") }}</div>
            </div>
            <div class="gd-r end">
              <div class="hfneir">{{ $t("m.dwcl") }}</div>
            </div>
          </div>

          <div class="gd-list-item" v-if="end.status == 3">
            <div class="gd-l">
              <div class="imico">{{ $t("m.nin") }}</div>
            </div>
            <div class="gd-r end">
              <div class="hfneir">{{ $t("m.yjj") }}</div>
            </div>
          </div>
        </div>
      </div>

      <div class="bttonm" v-if="end.status != 3">
        <div class="flexsa">
          <div class="btnsd scllow" @click="guanbi()">{{ $t("m.gbgd") }}</div>
          <div class="btnsd scllow" @click="goto('jxly')">
            {{ $t("m.jxly") }}
          </div>
        </div>
      </div>
      <div class="bttonm" v-else></div>
    </div>
  </div>
</template>

<script>
import { ImagePreview } from "vant";
export default {
  name: "name",
  data() {
    return {
      isPublish: false,
      oid: "",
      gdata: [],
      topimglist: [],
      end: [],
    };
  },
  created() {
    this.oid = sessionStorage.getItem("gddata");
    this.getgdata();
  },
  mounted() {
    if (window.history && window.history.pushState) {
      history.pushState(null, null, document.URL);
      window.addEventListener("popstate", this.goBack, false);
    }
  },
  destroyed() {
    window.removeEventListener("popstate", this.goBack, false);
  },
  methods: {
    goBack() {
      this.$router.push({ path: "wdgd" });
    },
    seeimg(val) {
      ImagePreview(val);
    },
    guanbi() {
      this.$dialog
        .confirm({
          title: this.$i18n.t("m.txt"),
          message: this.$i18n.t("m.qrgb"),
        })
        .then(() => {
          if (this.$store.getters.nameid) {
            let datas = {
              uid: this.$store.getters.nameid,
              id: this.oid,
            };
            this.$post({
              url: "workOrder/completeWorkOrder",
              data: datas,
              callback: (data) => {
                this.$nextTick(function () {
                  var s = data.data;
                  if (s) {
                    this.$toast(this.$i18n.t("m.gbcg"));
                    this.$router.replace("wdgd");
                  } else {
                    this.$toast(data.message);
                  }
                });
              },
            }).catch(() => {
              this.$toast(this.$i18n.t("m.errordata"));
            });
          } else {
            this.getuid();
          }
        });
    },
    getuid() {
      this.$get({
        url: "wms-wallet/user-game-info/" + this.$store.getters.userWallet,
        data: {},
        callback: (data) => {
          this.$nextTick(function () {
            if (data.data) {
              this.$store.commit("nameid", data.data.id);
              this.guanbi();
            }
          });
        },
      }).catch(() => {
        this.$toast(this.$i18n.t("m.errordata"));
      });
    },
    goto(val) {
      this.$router.push({ path: val });
    },
    forimg(val) {
      var img = val.split(",");
      var imglist = img.map((val) => {
        return (
          "https://bc-1302771921.cos.ap-nanjing.myqcloud.com/images/" + val
        );
      });
      console.log(imglist);
      return imglist;
    },
    getgdata() {
      if (this.oid) {
        var datas = {
          params: {
            oid: this.oid,
          },
        };
        this.$get({
          url: "workOrder/getContentList",
          data: datas,
          callback: (data) => {
            this.$nextTick(function () {
              var list = data.data;
              if (list) {
                this.gdata = list.workContent;
                if (this.gdata[0].imgs) {
                  this.topimglist = this.forimg(this.gdata[0].imgs);
                }
                this.end = list.workOrder;
              } else {
                this.$toast(data.msg);
              }
            });
          },
        }).catch(() => {
          this.$toast(this.$i18n.t("m.errordata"));
        });
      }
    },
  },
};
</script>

<style lang="scss" scoped>
</style>